<template>
  <a-table :columns="columns" :data="formData" :pagination="false">
    <template #index="{ rowIndex }">
      {{ rowIndex + 1 }}
    </template>
    <template #weight="{ rowIndex }">
      {{ formData[rowIndex].weight ? formData[rowIndex].weight : '--' }}
    </template>
    <template #status="{ rowIndex }">
      {{ getStatuName(formData[rowIndex].optionStatus) }}
    </template>
    <template #cycle="{ rowIndex }">
      {{ formData[rowIndex].cycleStart }} 至
      {{ formData[rowIndex].cycleEnd }}
    </template>

    <template #optional="{ rowIndex }">
      <a-button
        v-if="formData[rowIndex].optionStatus === 1"
        @click="toolSet(rowIndex)"
      >
        创建
      </a-button>
      <a-button
        v-if="formData[rowIndex].optionStatus === 2"
        @click="toolSet(rowIndex)"
      >
        编辑
      </a-button>
      <a-button
        v-if="formData[rowIndex].optionStatus === 3"
        @click="toolSet(rowIndex)"
      >
        详情
      </a-button>
    </template>
  </a-table>
</template>
<script setup lang="ts">
import type {
  ProbationExamine,
  PersonnelAssessmentOptionLevel,
  PersonnelUserExaminationRules
} from '@/apis/human/base/variationManager/probation/type';
import { useVModel } from '@vueuse/core';

const props = withDefaults(
  defineProps<{
    data: (ProbationExamine & { isInput?: boolean })[];
    currentProgrammeIndex: number;
  }>(),
  {}
);
const emit = defineEmits([
  'update:data',
  'update:currentProgrammeIndex',
  'selectChange'
]);

const formData = useVModel(props, 'data', emit);
const selectIndex = useVModel(props, 'currentProgrammeIndex', emit);
const columns = ref<any>([
  {
    title: '序号',
    dataIndex: '',
    slotName: 'index',
    width: 80
  },
  {
    title: '考核方案名称',
    dataIndex: 'name',
    width: 200
  },
  {
    title: '状态',
    dataIndex: 'status',
    slotName: 'status',
    width: 100
  },
  {
    title: '方案权重',
    dataIndex: 'weight',
    slotName: 'weight',
    width: 100
  },
  {
    title: '考核周期',
    dataIndex: 'cycle',
    slotName: 'cycle',
    width: 200
  },
  {
    title: '预警提醒时间',
    dataIndex: 'earlyWarningTime',
    slotName: 'earlyWarningTime',
    width: 200
  },
  {
    title: '启动时间',
    dataIndex: 'startTime',
    slotName: 'startTime',
    width: 200
  },
  {
    title: '操作',
    dataIndex: 'optional',
    slotName: 'optional',
    width: 100,
    align: 'center'
  }
]);
const toolSet = (index: number) => {
  if (!formData.value[index].personnelAssessmentOptionDimensionality)
    formData.value[index].personnelAssessmentOptionDimensionality = [];
  selectIndex.value = index;
  emit('selectChange');
};
const getStatuName = (n?: number) => {
  switch (n) {
    case 1:
      return '待创建';
    case 2:
      return '待提交';
    case 3:
      return '待确认';
    case 4:
      return '已退回';
    case 5:
      return '已生效';
    case 6:
      return '变更中';
    case 7:
      return '变更中';
    case 8:
      return '待自评';
    case 9:
      return '待评分';
    case 10:
      return '结果待确认';
    case 11:
      return '已确认';
    case 12:
      return '结果拒绝';
    case 13:
      return '结果拒绝';
    case 14:
      return '方案不通过';
    case 15:
      return '结果申诉';
    case 16:
      return '已结束';
    case 17:
      return '已结束';
    case 18:
      return '申诉超时';
    case 19:
      return '已生效';
    case 20:
      return '已生效';
    default:
      return '无状态';
  }
};
</script>
<style lang="less" scoped></style>
